package com.ericsson.eritask.dao;

import java.util.List;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.ericsson.eritask.domain.Role;
import com.ericsson.eritask.domain.User;
import com.ericsson.eritask.domain.UserRole;


//@Repository
public class JdbcUserDAO {/*

	@PersistenceContext
	private EntityManager entitymanager;

	private Set<Role> rs;

	private List<User> user;
	private List<UserRole> userRoles;
	//int roleId;
	private User u;
	private Role r;

	private UserRole userRole;


	@Override
	@Transactional
	public void insert(User user) {

		//entitymanager.persist(user);

	}

	@Transactional
	public void getUserRole(String roleName,String signum){

		//User u = new User();
		//Role r = new Role();
		
		Query query = entitymanager.createNamedQuery("Role.findRoleByRolename",Role.class);

		query.setParameter("roleName", roleName);
		List<Role> list = query.getResultList( );

		for( Role e:list ) {
			System.out.print("Role ID :" + e.getRoleId());
			System.out.println("\t Role Name :" + e.getRoleName());

			if(e.getRoleId()!= 0){
				int roleId = e.getRoleId();
				UserRole ur = new UserRole();
				
				
				Query qr = entitymanager.createNamedQuery("UserRole.ifExists",UserRole.class);
				qr.setParameter("signum", signum);
				qr.setParameter("roleId", roleId);
				
				List<UserRole> ls = qr.getResultList();
				if(ls.isEmpty()==false){
				for(UserRole usr : ls){
					System.out.print("User Role ID :" + usr.getUserRoleID());
					System.out.print("Role ID :" + usr.getRole().getRoleId());
					System.out.println("\tsignum :" + usr.getUser().getSignum());
					
				}
				
				
				
				}else{
					addUserRole(signum,roleId);
				//}
				
				System.out.println("here");
				
				
				String queryUR = "insert into UserRole (roleId, signum) values (?, ?) where roleId = :roleId";

				entitymanager.createQuery(queryUR,UserRole.class);
			}



		}



	}






	@Override
	public List<User> findAll() {

		return null;

		//return (List<User>) entitymanager.find(User.class, "signum");
	}



	@Override
	@Transactional
	public void addUserRole(String userid,int roleId) {

		UserRole uRole =new UserRole();
		uRole.setRole(entitymanager.find(Role.class, roleId));
		uRole.setUser(entitymanager.find(User.class, userid));


		entitymanager.persist(uRole);


	}



	@Override
	@Transactional
	public void getAllUserRoles(String userId) {

		User u = entitymanager.find(User.class, userId);
		List<UserRole> currentRoles = u.getAllroles();

		UserRole uRole =new UserRole();
		uRole.setUser(u);
		uRole.setRole(entitymanager.find(Role.class, 1));
		currentRoles.add(uRole);

		entitymanager.persist(u);



	}

*/}
